package com.mediator;

import java.util.HashMap;

// 具体的中介者类
public class ConcreteMediator extends Mediator{
    // 集合，放入所有的同事对象
    private HashMap<String, Colleague> colleagueMap;
    private HashMap<String, String> interMap;

    public ConcreteMediator() {
        this.colleagueMap = new HashMap<>();
        this.interMap = new HashMap<>();
    }

    @Override
    public void Register(String colleageName, Colleague colleague) {
        colleagueMap.put(colleageName, colleague);
        if(colleague instanceof Alarm){
            interMap.put("Alarm", colleageName);
        } else if (colleague instanceof  TV){
            interMap.put("TV", colleageName);
        } else if (colleague instanceof Curtains){
            interMap.put("Curtains", colleageName);
        } else if (colleague instanceof CoffeeMachine){
            interMap.put("CoffeeMachine", colleageName);
        }
    }

    // 具体中介者的核心方法
    // 1.根据得到消息，完成对应任务
    // 2.中介者在这个方法，协调各个具体的同事对象，完成任务
    @Override
    public void getMessage(int stateChange, String colleageName) {
        if(colleagueMap.get(colleageName) instanceof Alarm){
            if(stateChange == 0){
                ((CoffeeMachine)(colleagueMap.get(interMap.get("CoffeeMachine")))).StartCoffee();
                ((TV)(colleagueMap.get(interMap.get("TV")))).StartTv();
            } else if (stateChange == 1){
                ((TV)(colleagueMap.get(interMap.get("TV")))).StopTv();
            }
        } else if(colleagueMap.get(colleageName) instanceof CoffeeMachine){
            ((Curtains)(colleagueMap.get(interMap.get("Curtains")))).UpCurtains();
        } else if (colleagueMap.get(colleageName) instanceof TV){

        } else if (colleagueMap.get(colleageName) instanceof Curtains){

        }
    }

    @Override
    public void SendMessage() {

    }
}
